﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HostAssistantCore
{
    #region TextBox 文本框水印文字
    /// <summary>
    /// 基于.NET 2.0的TextBox工具类
    /// </summary>
    public static class TextBoxToolV2
    {

        public static void SetWatermark(this TextEdit textEdit, string watermark)
        {
            textEdit.Properties.NullValuePromptShowForEmptyValue = true;
            textEdit.Properties.NullValuePrompt = watermark;
        }
        public static void ClearWatermark(this TextEdit textEdit)
        {
            if (textEdit.Properties.NullValuePromptShowForEmptyValue)
                textEdit.Properties.NullValuePrompt = string.Empty;
        }



        //private const int EM_SETCUEBANNER = 0x1501;
        //[DllImport("user32.dll", CharSet = CharSet.Auto)]

        //private static extern Int32 SendMessage
        // (IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);

        ///// <summary>
        ///// 为TextBox设置水印文字
        ///// </summary>
        ///// <param name="textBox">TextBox</param>
        ///// <param name="watermark">水印文字</param>
        //public static void SetWatermark(this TextBox textBox, string watermark)
        //{
        //    SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermark);
        //}
        ///// <summary>
        ///// 清除水印文字
        ///// </summary>
        ///// <param name="textBox">TextBox</param>
        //public static void ClearWatermark(this TextBox textBox)
        //{
        //    SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, string.Empty);
        //}
    }

    #endregion
}
